<template>
	<view class="content">
		<moveMenu v-if="showDeepSeek == 1" ref="moveMenu"></moveMenu>
		<scroll-view class="scroll-view_H" scroll-y="true" @scroll="scroll">
			<view class="courtyard-area">
				<img style="width: 100%;" src="@/static/images/homeIndex/top-bg.png"></img>
				<view class="hosp-name flex align-center" @click="selectHospital">
					<text>{{currentHospital}}</text>
					<img class="m-l-10" src="@/static/images/homeIndex/hosp-name-suffix.svg"></img>
				</view>
			</view>
			<view v-if="visitList.length>0" class="current-visit-card">
				<view class="content flex align-center">
					<view class="left flex flex-column justify-between" style="flex: 1;height: 100%;">
						<view class="flex align-center">
							<!-- <text style="font-size: 34rpx;color: #3C537D;">{{$desensitizationName(currentVisitInfo.name)}}</text> -->
							<text style="font-size: 34rpx;color: #3C537D;">{{currentVisitInfo.name}}</text>
							<!-- <text style="font-size: 34rpx;color: #3C537D;opacity: 0;">【门诊】</text> -->
							<view class="flex align-center m-l-30 p-l-16 p-r-16 p-t-8 p-b-8 switch-but" @click="open">
								<img style="width: 34rpx;" src="@/static/images/homeIndex/switch-card.svg" alt="">
								<text class="color-fff m-l-10">切换</text>
							</view>
						</view>
						<view class="flex flex-column">
							<text style="font-size: 30rpx;line-height: 60rpx;color: #3C537D;">卡号</text>
							<text style="letter-spacing: 4rpx; font-size: 36rpx;line-height: 40rpx;color: #3C537D;">{{$desensitizationNormalStr(currentVisitInfo.cardNum)}}</text>
						</view>
					</view>
					<view @click="showErcode">
						<QrCode :id="'QrCode'" :width="83" :height="83" :codeUrl="currentVisitInfo.cardNum" />
					</view>

					<!-- <img class="ercode" :src="currentVisitInfo.qrCode" @click="showErcode"></img> -->
				</view>
			</view>
			<!-- <view  @click="toMessage">消息列表</view> -->
			<view class="visit-function p-t-15 p-b-20">
				<view class="content flex">
					<view class="flex flex-column p-t-30 p-l-20 register" @click="toRegister">
						<view class="flex align-center p-r-20 justify-between">
							<text class="color-fff f-bold f-s-32">预约挂号</text>
							<img style="width: 22rpx;" src="@/static/images/homeIndex/visit-suffix.svg" alt="">
						</view>
						<text class="p-t-15" style="color: rgba(255, 255, 255, 0.9);font-size: 12px;">挂号不排队</text>
						<view class="flex justify-end bottom-icon">
							<img style="width: 100rpx;" src="@/static/images/homeIndex/register-bg.png" alt="">
						</view>
					</view>
					<view class="flex flex-column p-t-30 p-l-20 pay" @click="toRecharge">
						<view class="flex align-center p-r-20 justify-between">
							<text class="color-fff f-bold f-s-32">就医缴费</text>
							<img style="width: 22rpx;" src="@/static/images/homeIndex/visit-suffix.svg" alt="">
						</view>
						<text class="p-t-15" style="color: rgba(255, 255, 255, 0.9);font-size: 12px;">缴费更便捷</text>
						<view class="flex justify-end bottom-icon">
							<img style="width: 100rpx;" src="@/static/images/homeIndex/pay-bg.png" alt="">
						</view>
					</view>
					<view class="flex flex-column p-t-30 p-l-20 report" @click="checkReport">
						<view class="flex align-center p-r-20 justify-between">
							<text class="color-fff f-bold f-s-32">检查报告</text>
							<img style="width: 22rpx;" src="@/static/images/homeIndex/visit-suffix.svg" alt="">
						</view>
						<text class="p-t-15" style="color: rgba(255, 255, 255, 0.9);font-size: 12px;">专家免费解读</text>
						<view class="flex justify-end bottom-icon">
							<img style="width: 100rpx;" src="@/static/images/homeIndex/report-bg.png" alt="">
						</view>
					</view>
				</view>
			</view>
			<view class="function-module m-t-15 p-t-15 p-b-15">
				<view class="content flex flex-wrap">
					<view class="item" v-for="(item,index) in mySelfMenu" :key="index">
						<view v-if="item.skipType == '4'" style="width: 100%;height: 100%;position: relative;">
							<view class="flex flex-column align-center p-t-10 p-b-10">
								<view class="ico-shadow">
									<img style="width: 60rpx;height: 60rpx;"
										:src="require('@/static/svg/'+item.icon+'.svg')" alt="">
								</view>
								<text class="p-t-10 p-b-10"
									:style="[{'fontWeight':(item.isBold=='1'?'bold':'normal')},{'fontSize':item.fontSize+'rpx'},{'color':item.fontColour}]">{{item.name}}</text>
							</view>
							<wx-open-launch-weapp :appid="item.reserve"
								:path="decodeURIComponent(item.skipAddress) || '/'"
								style="position: absolute;left: 0;top: 0;width: 100%;height: 100%; opacity:0;z-index: 9999;-webkit-tap-highlight-color:transparent !important;">
								<script type="text/wxtag-template">
									<button style="position: absolute;left: 0;top: 0;width: 100%;height:100%;opacity:0;z-index: 9999;-webkit-tap-highlight-color:transparent !important;"></button>
								</script>
							</wx-open-launch-weapp>
						</view>
						<view v-else class="flex flex-column align-center p-t-10 p-b-10" @click="toMenuDetail(item)">
							<view class="ico-shadow">
								<img style="width: 60rpx;height: 60rpx;"
									:src="require('@/static/svg/'+item.icon+'.svg')" alt="">
							</view>
							<text class="p-t-10 p-b-10"
								:style="[{'fontWeight':(item.isBold=='1'?'bold':'normal')},{'fontSize':item.fontSize +'rpx'},{'color':item.fontColour}]">{{item.name}}</text>
						</view>

					</view>

					<view class="item flex flex-column align-center p-t-10 p-b-10" @click="editFunction">
						<view class="ico-shadow" style="padding: 20rpx;">
							<img style="width: 60rpx;" src="@/static/images/homeIndex/function-ico.png" alt="">
						</view>
						<text class="p-t-10 p-b-10 f-bold" style="font-size: 28rpx;">全部功能</text>
					</view>
				</view>
			</view>
			<view class="swiper-module m-t-15">
				<view class="content p-t-20 p-b-20">
					<!-- <u-swiper :list="bannersList" keyName="imgBanner" indicator @click="swiperClick"
						indicatorActiveColor="#4D8EFF" indicatorInactiveColor="#fff" indicatorMode="line" circular>
					</u-swiper> -->

					<swiper class="swiper" circular :indicator-dots="indicatorDots" indicator-color="#4D8EFF"
						indicator-active-color="#fff" :autoplay="autoplay" :interval="interval" :duration="duration">
						<swiper-item v-for="(item,index) in bannersList" :key="index" @click="swiperClick(index)">
							<view class="swiper-item uni-bg-red">
								<img style="width: 100%;height:auto;" :src="item.imgBanner" alt="">
							</view>
						</swiper-item>
					</swiper>
				</view>
			</view>

			<view class="department-doctor m-t-15 p-b-20">
				<u-tabs :list="list1" @click="clickTabs"></u-tabs>
				<!-- 医师 -->
				<view v-show="showDeapartDoctor" class="content p-t-10 p-l-20 p-r-20 p-b-20 m-t-15">
					<view class="item flex align-center p-t-5 p-b-5" v-for="(item,index) in doctorList" :key="index"
						@click="toDoctorDetail(item)">
						<u--image width="60" height="60"
							:src="item.doctorImg?item.doctorImg:item.sex=='2'?require('@/static/images/homeIndex/doct-g.png'):item.sex=='1'?require('@/static/images/homeIndex/doct-m.png'):require('@/static/images/homeIndex/avator-doctor.png')"
							shape="circle"></u--image>
						<view style="height: 100%;flex: 1;"
							class="flex flex-column justify-around p-l-16 p-t-10 p-b-10">
							<view class="flex align-center justify-between m-b-10">
								<view class="flex align-center">
									<text style="font-size: 32rpx;color: #323232;">{{item.doctorName}}</text>
									<text
										style="font-size: 32rpx;color: #323232;margin-left: 12rpx;">{{item.deptName}}</text>
								</view>

								<img style="width: 40rpx;" src="@/static/images/arrow-right.svg" alt="">
							</view>
							<text class="overEllips"
								style="font-size: 26rpx;color: #999999;">{{item.articleTitle}}</text>
						</view>
					</view>

					<view class="more flex align-center justify-center p-t-20 p-b-20" @click="moreDoctor">
						<text>查看更多</text>
						<text style="color: #4D8EFF;">{{currentHospital}}</text>
						<text>医生</text>
						<img style="width: 40rpx;" src="@/static/images/arrow-right.svg" alt="">
					</view>
				</view>
				<!-- 科室介绍 -->
				<view v-show="!showDeapartDoctor" class="content p-t-10 p-l-20 p-r-20 p-b-20 m-t-15">
					<view class="item flex align-center p-t-5 p-b-5" v-for="(item,index) in deptList" :key="index"
						@click="toDeptDetail(item)">
						<u--image width="60" height="60"
							:src="item.deptImg?item.deptImg:require('@/static/images/homeIndex/dept-ico.png')"
							shape="circle"></u--image>
						<view style="height: 100%;flex: 1;"
							class="flex flex-column justify-around p-l-16 p-t-10 p-b-10">
							<view class="flex align-center justify-between m-b-10">
								<text style="font-size: 32rpx;color: #323232;">{{item.deptName}}</text>
								<img style="width: 40rpx;" src="@/static/images/arrow-right.svg" alt="">
							</view>
							<text class="overEllips"
								style="font-size: 26rpx;color: #999999;">{{item.articleTitle}}</text>
						</view>
					</view>
					<view class="more flex align-center justify-center p-t-20 p-b-20" @click="moreDept">
						<text>查看更多</text>
						<text style="color: #4D8EFF;">{{currentHospital}}</text>
						<text>科室</text>
						<img style="width: 40rpx;" src="@/static/images/arrow-right.svg" alt="">
					</view>
				</view>
			</view>
		</scroll-view>

		<!-- 首次选择院区 -->
		<u-popup :show="showCourtyardArea" :customStyle="{'width':'94%'}" :round="10" :safeAreaInsetBottom="true"
			mode="center">
			<view class="top-bar flex align-center p-l-30 p-r-30 p-t-20 p-b-20">
				<text class="f-s-34">请选择院区</text>
			</view>
			<view style="height: 50vh;" class="p-b-20">
				<scroll-view class="scroll-view_visit" scroll-y="true">
					<view class="card-item flex p-t-20 p-b-20 p-l-30 p-r-40" v-for="(item,index) in courtyardAreaList"
						:key="index" @click="firstSelectHospital(item)">
						<view class="flex flex-column" style="flex: 1;">
							<view class="flex align-center m-b-20">
								<text class="f-s-32 color-323232">{{item.name}}</text>
							</view>
							<view class="flex align-center f-s-28 color-666">
								<img style="width: 40rpx;" src="@/static/images/homeIndex/location-ico.png" alt="">
								<text>{{item.address}}</text>
							</view>
						</view>
						<view class="flex align-center justify-center">
							<text class="select-visit f-s-28">选择</text>
						</view>
					</view>
				</scroll-view>
			</view>
		</u-popup>

		<!-- 切换就诊人 -->
		<u-popup :show="showVisitCard" :round="10" :safeAreaInsetBottom="true" mode="bottom">
			<switchVisitCard :visitData="visitList" :relations="relationTrans" @closeVisit="close" />
		</u-popup>
		<!-- 就诊二维码 -->
		<u-popup :show="showVisitErcode" :customStyle="{'width':'94%'}" :round="10" :safeAreaInsetBottom="true"
			mode="center" @close="closeErcode">
			<view class="top-bar flex align-center justify-end p-t-30 p-r-30">
				<img style="width: 34rpx;" src="@/static/images/homeIndex/close-ico.png" @click="closeErcode"></img>
			</view>
			<view class="ercode-pop flex flex-column align-center p-b-40">
				<!-- <img class="avatar" src="@/static/images/homeIndex/avator-doctor.png" alt=""> -->
				<u--image width="70" height="70" :src="currentVisitInfo.headImg" shape="circle"></u--image>
				<!-- <text class="color-323232 f-s-36 f-bold m-t-15 m-b-15">{{$desensitizationName(currentVisitInfo.name)}}</text> -->
				<text class="color-323232 f-s-36 f-bold m-t-15 m-b-15">{{currentVisitInfo.name}}</text>
				<text class="color-888 f-s-30"
					style="letter-spacing: 6rpx;">卡号：{{$desensitizationNormalStr(currentVisitInfo.cardNum)}}</text>
				<!-- <img class="ercode" :src="currentVisitInfo.qrCode"></img> -->
				<QrCode :id="'QrCode'" :width="260" :height="260" :codeUrl="currentVisitInfo.cardNum" />
				<text class="f-s-28" style="color: #FF7C4D;">温馨提示</text>
				<text class="f-s-28 m-t-15" style="text-align: center;">就诊时请出示就诊码就诊二维码是实时有效的，请不要使用截图就诊</text>
			</view>
		</u-popup>
		<!-- 挂号须知 -->
		<u-popup :show="registerKnowe" :customStyle="{'width':'90%'}" :round="10" :safeAreaInsetBottom="true"
			mode="center">
			<view class="top-bar flex align-center justify-center p-t-20 p-b-20">
				<text class="color-323232 f-s-36 f-bold">挂号须知</text>
			</view>
			<view class="ercode-pop flex flex-column p-b-20">
				<scroll-view style="width: 100%;height: 60vh;padding-bottom: 20rpx;" scroll-y="true">
					<text
						style="font-size: 28rpx;line-height: 40rpx; color: #323232;letter-spacing: 3px;">{{registerKnownContent}}</text>
				</scroll-view>
				<u-button type="primary" style="width:90%;" @click.native="readDone">已阅读</u-button>
			</view>
		</u-popup>
		<!-- loading -->
		<u-overlay :show="loading" :opacity="0.8">
			<view class="warp">
				<view class="rect" @tap.stop>
					<view class="lds-ripple">
						<view></view>
						<view></view>
					</view>
				</view>
			</view>
		</u-overlay>
	</view>
</template>

<script>
	import moveMenu from "@/pages/mine/moveMenu/index.vue";
	import switchVisitCard from '@/components/switchVisitCard/index.vue';
	import QrCode from '@/components/qrcode/index.vue';
	import {
		getDoctorList,
		getDeptList,
		getAllHospital,
		getTrtendsList,
		getVisitorList,
		getConfigMenuList,
		getAllmenuFunction,
		jumpToProgram,
		getConfigKey
	} from "@/api/home/home.js";
	import config from "@/config.js";
	import {
		patientBase,
		getInfoMatch
	} from '@/api/card/index.js'
	import {
		getDictType
	} from "@/api/system/public.js";
	import wx from 'weixin-js-sdk'
	import {
		arrNoRepeat,
		getQueryString,
		idCard
	} from "@/utils/common.js";
	import aes from "@/utils/Encryption.js";
	import {
		getInpatientInfo
	} from "@/api/beInHospital/index.js"
	import {
		EventBus
	} from "@/utils/event-bus.js";
	export default {
		components: {
			switchVisitCard,
			QrCode,
			moveMenu
		},
		data() {
			return {
				indicatorDots: true,
				autoplay: true,
				interval: 2000,
				duration: 500,
				loading: false,
				visitList: [],
				doctorList: [],
				deptList: [],
				list1: [{
					name: '医生列表',
				}, {
					name: '科室介绍',
				}],
				currentHospital: '',
				hospitalCode: '',
				bannersList: [
					{
						imgBanner: require('@/static/images/homeIndex/swiper-img.png')
					}
				],
				showDeapartDoctor: true, //切换医师&部门
				showVisitCard: false, //选择就诊人
				showVisitErcode: false,
				showCourtyardArea: false, //首次进入选择院区
				courtyardAreaList: [], //所有院区
				relationTrans: {},
				sexTrans: {},
				currentVisitInfo: {
					name: '',
					cardNum: '',
					qrCode: '',
					headImg: ''
				},
				mySelfMenu: [],
				registerKnowe: false,
				jumpTypeCode: '1',
				registerKnownContent: '',
				showDeepSeek:'',
			}
		},
		onLoad: function() {
			this.getConfig()
			this.initConfig()
			/* 获取字典 */
			this.getDict()
			let _that = this;
			var baseUrl = window.location.href.split('/')[3];// 获取公众号配置地址
			EventBus.$on('homeIndex', function(res) {
				if (res != '') {
					_that.currentHospital = res.name
					_that.hospitalCode = res.hospitalCode
				} else {
					// 2024-12-19 首次授权后 直接存当前公众号openid
					var openid = uni.getStorageSync('openid');
					var activeOpenId = baseUrl+openid;
					uni.setStorageSync(activeOpenId, openid);
					
					_that.getConfigOutSideJump()
					_that.init()
					_that.getVisitor()
					_that.getFunctionList()
				}

			})
			EventBus.$on('loadFunction', function(res) {
				_that.getFunctionList()
			})
			EventBus.$on('loadVisitor', function(res) {
				_that.getVisitor()
			})

			let hospital = uni.getStorageSync('hospital'+baseUrl)
			if (hospital == '') {
				this.getAllCourtyardArea()
			} else {
				this.currentHospital = JSON.parse(hospital).name
				this.hospitalCode = JSON.parse(hospital).hospitalCode
				this.init()
				this.getVisitor()
				this.getFunctionList()
			}
			EventBus.$on('outSideJump', function(res) {
				_that.getConfigOutSideJump()
			})
		},
		onPullDownRefresh() {
			this.checkOpenId();
			this.getConfig()
			this.init()
			this.getVisitor()
			this.getFunctionList()
		},
		methods: {
			checkOpenId(){
				// 2024-12-18 解决不同公众号对应openid不同问题
				var baseUrl = window.location.href.split('/')[3];// 获取公众号配置地址
				var openid = uni.getStorageSync('openid');
				var activeOpenId = baseUrl+openid;
				
				let url = window.location.href;
				// 判断当前公众号下是否存在openid
				if(!uni.getStorageSync(activeOpenId) || !openid){
					if (url.indexOf('?') !== -1) {
					  url = url.replace(/(\?|#)[^'"]*/, '')
					  window.history.pushState({}, 0, url)
					}
					uni.setStorageSync('hospital','');
					uni.setStorageSync('hospital'+baseUrl,'');
					this.$store.dispatch('WXLogin');
				}
			},
			/* 是否开启对接外部跳转 */
			getConfigOutSideJump() {
				let openid = uni.getStorageSync('openid') || ''
				getConfigKey('sys_outside_link_jump').then(res => {
					if (res.msg == '1') {
						if (uni.getStorageSync('userId') != '' && openid != '') {
							this.jzswjw(uni.getStorageSync('userId'))
						}
					} else {
						uni.removeStorageSync('jzjktFunc')
						uni.removeStorageSync('userId')
					}
				});
			},
			/* 回调接口获取用户信息 */
			jzswjw(userid) {
				let _that = this
				uni.request({
					url: 'https://jkt.jzswjw.gov.cn/AREAServer/user',
					method: 'GET',
					data: {
						userId: userid
					},
					success: (res) => {
						_that.judgeIsNoCreateCard(res.data.data)
					},
					fail: () => {}
				})

			},
			/* 判断回调来的用户是否已建卡 */
			judgeIsNoCreateCard(params) {
				let openid = uni.getStorageSync('openid') || ''
				var baseUrl = window.location.href.split('/')[3];// 获取公众号配置地址
				getVisitorList({
					hospitalCode: JSON.parse(uni.getStorageSync('hospital')).hospitalCode,
					openId: openid
				}).then(res => {
					/* 人员列表 */
					if (res.rows.length > 0) { //用户已建卡
						this.loadCardList({
							rows: JSON.parse(JSON.stringify(res.rows))
						})
						uni.removeStorageSync('userId')
						if (uni.getStorageSync('jzjktFunc') == 'appointment') { //预约挂号
							uni.navigateTo({
								url: '/pages/mine/selectDepartment/index?registerType=1'
							})
						}
						if (uni.getStorageSync('jzjktFunc') == 'onlinecharge') { //在线缴费
							uni.navigateTo({
								url: '/pages/pay/index'
							})
						}
						if (uni.getStorageSync('jzjktFunc') == 'reportlist') { //报告查询
							uni.navigateTo({
								url: '/pages/mine/report/index'
							})
						}
						uni.removeStorageSync('jzjktFunc')
					} else { //用户未建卡默认建卡
						this.autoCreatCard(params)
					}
				});
			},
			/* 自动建卡 */
			autoCreatCard(info) {
				if (uni.getStorageSync('openid')) {
					let openid = uni.getStorageSync('openid') || ''
					var baseUrl = window.location.href.split('/')[3];// 获取公众号配置地址
					let params = {
						address: '',
						headImg: this.$store.state.user.avatar,
						hospitalCode: JSON.parse(uni.getStorageSync('hospital')).hospitalCode,
						idNum: info.idNo,
						mobile: info.mobile,
						name: info.name,
						nation: '',
						nickName: this.$store.state.user.name,
						openId: openid,
						relation: '1',
						relationName: '本人',
						sex: idCard(info.idNo, 2) == '男' ? '1' : idCard(info.idNo, 2) == '女' ? '2' : ''
					}
					getInfoMatch({
						name: info.name,
						idNum: info.idNo
					}).then(ress => {
						if (ress.data && ress.data.patientCard) {
							params.cardNum = ress.data.patientCard
							params.feeType = ress.data.mediTreatement
							params.cardStatu = ress.data.cardType
							params.feeBalance = ress.data.cardBalance
						}
						if (uni.getStorageSync('userId') == '') {
							return
						}
						patientBase(params).then(res => {
							if (res.code == 200) {
								this.init()
								this.getVisitor()
								this.getFunctionList()
								uni.removeStorageSync('userId')
								if (uni.getStorageSync('jzjktFunc') == 'appointment') { //预约挂号
									uni.navigateTo({
										url: '/pages/mine/selectDepartment/index?registerType=1'
									})
								}
								if (uni.getStorageSync('jzjktFunc') == 'onlinecharge') { //在线缴费
									uni.navigateTo({
										url: '/pages/pay/index'
									})
								}
								if (uni.getStorageSync('jzjktFunc') == 'reportlist') { //报告查询
									uni.navigateTo({
										url: '/pages/mine/report/index'
									})
								}
								uni.removeStorageSync('jzjktFunc')
							}
						}).catch(errors => {});
					}).catch(errors => {});
				}
			},
			/* 获取参数配置 */
			getConfig() {
				getConfigKey('register_known').then(res => {
					this.registerKnownContent = res.msg
				});
				getConfigKey('isenabled').then(res => {
					this.showDeepSeek = res.msg;
				});
			},
			/* 注册小程序标签 */
			initConfig() {
				var params = {
					//不需要后面的hash值
					//服务器计算签名的时候需要用到当前网页的链接，且链接里不需要hash值，所以做这个处理
					url: window.location.href
				}
				jumpToProgram(params).then(res => {
					var a = res.data;
					wx.config({
						debug: false,
						appId: a.appId,
						timestamp: a.timestamp,
						nonceStr: a.nonceStr,
						signature: a.signature,
						jsApiList: ['onMenuShareTimeline'],
						openTagList: ['wx-open-launch-weapp']
					})
					wx.ready(() => {
						//这里是成功后执行
						// alert('成功')
					});
					wx.error(() => {
						//这里是出现异常执行
						// alert('失败')
					})
				});

			},
			init() {
				this.loading = true
				Promise.all([this.getDept(), this.getDoctor(), this.getTrends()]).then(result => {
					//数据请求完成之后停止下拉刷新
					uni.stopPullDownRefresh();
					this.loading = false
					/* 科室 */
					if (result[0].rows.length > 5) {
						this.deptList = result[0].rows.slice(0, 5).filter(item => item.isShow == '1')
					} else {
						this.deptList = result[0].rows.filter(item => item.isShow == '1')
					}
					/* 医生 */
					if (result[1].rows.length > 5) {
						this.doctorList = result[1].rows.slice(0, 5).filter(item => item.isShow == '1')
					} else {
						this.doctorList = result[1].rows.filter(item => item.isShow == '1')
					}
					/* 院内动态展示 */
					if (result[2].rows.length > 0) {
						let lists = []
						result[2].rows.forEach(item => {
							if (item.imgBanner != null && item.imgBanner != '' && item.isShow == '1') {
								lists.push(item)
							}
						})
						this.bannersList = lists
						// console.log(lists)
					} else {
						this.bannersList = [{
							imgBanner: require('@/static/images/homeIndex/swiper-img.png')
						}]
					}

				})
			},
			/* 首次选择院区 */
			firstSelectHospital(res) {
				let params = {
					name: res.name,
					hospitalCode: res.hospitalCode
				}
				var baseUrl = window.location.href.split('/')[3];// 获取公众号配置地址
				uni.setStorageSync('hospital', JSON.stringify(params) || '')
				uni.setStorageSync('hospital'+baseUrl, JSON.stringify(params) || '')
				this.showCourtyardArea = false
				this.currentHospital = res.name
				this.hospitalCode = res.hospitalCode
				this.init()
				this.getVisitor()
				this.getFunctionList()
			},
			/* 获取所有院区 */
			getAllCourtyardArea() {
				getAllHospital().then(res => {
					// console.log(res)
					this.courtyardAreaList = res.rows.filter(item => item.parentCode != 0)
					if (this.courtyardAreaList.length == 1) {
						this.firstSelectHospital(this.courtyardAreaList[0])
					} else {
						this.showCourtyardArea = true
					}

				});
			},
			/* 获取所有功能菜单列表 */
			getFunctionList() {
				getAllmenuFunction().then(res => {
					this.getMenuList(res)
				});
			},
			/* 获取患者自定义的菜单列表 */
			getMenuList(data) {
				let openid = uni.getStorageSync('openid') || ''
				getConfigMenuList({
					openId: openid
				}).then(res => {
					/* 自定义菜单 */
					let results = []
					res.rows.forEach(item => {
						for (let i in data.rows) {
							if (item.menuCode == data.rows[i].menuCode) {
								results.push(data.rows[i])
							}
						}
					})
					let h = data.rows.filter(item => item.isIndex == '1')
					this.mySelfMenu = h.concat(results).filter(item => item.valid == '1')
					this.mySelfMenu = arrNoRepeat(this.mySelfMenu, 'menuCode')
				});
			},
			/* 跳转功能页面 */
			toMenuDetail(res) {
				/* skipType:1路由详情，2路由列表，3第三方url，4小程序，5功能页面 */
				if (res.skipType == '1') {
					uni.navigateTo({
						url: '/pages/home/menuDetail?id=' + res.id + '&menuCode=' + res.menuCode + '&menuName=' +
							res.name
					})
				}
				if (res.skipType == '2') {
					uni.navigateTo({
						url: '/pages/home/menuList?id=' + res.id + '&menuCode=' + res.menuCode + '&menuName=' + res
							.name
					})
				}
				if (res.skipType == '3') {
					if (decodeURIComponent(res.skipAddress).includes('{name}') || decodeURIComponent(res.skipAddress)
						.includes('{idNum}') || decodeURIComponent(res.skipAddress).includes('{cardNum}') ||
						decodeURIComponent(res.skipAddress).includes('{HospitalCode}') || decodeURIComponent(res
							.skipAddress).includes('{openid}')) {
						if (uni.getStorageSync('currentVisitCard') == '') {
							this.$tab.navigateTo('/pages/addHealthCard/index')
						} else {
							let str = decodeURIComponent(res.skipAddress)
							var baseUrl = window.location.href.split('/')[3];// 获取公众号配置地址
							let username = JSON.parse(uni.getStorageSync('currentVisitCard')).name || ''
							let useridNum = JSON.parse(uni.getStorageSync('currentVisitCard')).idNum || ''
							let usercardNum = JSON.parse(uni.getStorageSync('currentVisitCard')).cardNum || ''
							let hospitalCode = JSON.parse(uni.getStorageSync('hospital')).hospitalCode || ''
							let openid = uni.getStorageSync('openid') || ''
							let resultUrl = str.replace('{name}', username).replace('{idNum}', useridNum)
								.replace('{cardNum}', usercardNum).replace('{HospitalCode}', hospitalCode).replace(
									'{openid}', openid);
							// console.log(resultUrl, '------满意度调查-------------')
							// uni.navigateTo({
							// 	url: '/pages/home/webview?url=' + resultUrl + '&title=' + res
							// 		.name
							// })
							window.location.href = resultUrl
						}
					} else {
						// uni.navigateTo({
						// 	url: '/pages/home/webview?url=' + decodeURIComponent(res.skipAddress) + '&title=' + res
						// 		.name
						// })
						if (decodeURIComponent(res.skipAddress).includes('{patentid}')) {
							if (uni.getStorageSync('currentVisitCard') == '') {
								this.$tab.navigateTo('/pages/addHealthCard/index')
							} else {
								let str = decodeURIComponent(res.skipAddress)
								let usercardNum = JSON.parse(uni.getStorageSync('currentVisitCard')).cardNum || ''
								let resultUrl = str.replace('{patentid}', aes.encrypt(usercardNum));
								// console.log(resultUrl, '------AES加密-------------')
								window.location.href = decodeURIComponent(resultUrl)
							}
						} else {
							window.location.href = decodeURIComponent(res.skipAddress)
						}

					}
				}
				if (res.skipType == '5') {
					if (res.name == '预约挂号' || res.name == '当班挂号') {
						if (uni.getStorageSync('currentVisitCard') == '') {
							this.$tab.navigateTo('/pages/addHealthCard/index')
						} else {
							this.registerKnowe = true
							this.jumpTypeCode = res.name == '预约挂号' ? '1' : '2'
						}
					} else {
						if (res.name == '门诊缴费' || res.name == '押金缴纳' || res.name == '一日清单' || res.name == '挂号记录' || res
							.name == '押金记录') {
							if (uni.getStorageSync('currentVisitCard') == '') {
								this.$tab.navigateTo('/pages/addHealthCard/index')
							} else {
								let params = {
									name: JSON.parse(uni.getStorageSync('currentVisitCard')).name || '',
									idNum: JSON.parse(uni.getStorageSync('currentVisitCard')).idNum || ''
								}
								if (res.name == '押金缴纳' || res.name == '一日清单' || res.name == '押金记录') {
									getInpatientInfo(params).then(result => {
										uni.navigateTo({
											url: decodeURIComponent(res.skipAddress)
										})
									}).catch(errors => {
										if(errors == '没有找到住院信息！' && res.name == '押金缴纳'){
											uni.navigateTo({
												url: '/pages/home/inHos'
											})
										}
									});
								} else {
									uni.navigateTo({
										url: decodeURIComponent(res.skipAddress)
									})
								}
							}
						} else {
							uni.navigateTo({
								url: decodeURIComponent(res.skipAddress)
							})
						}
					}
				}

			},
			/* 获取就诊人列表 */
			getVisitor() {
				let openid = uni.getStorageSync('openid') || ''
				getVisitorList({
					hospitalCode: this.hospitalCode,
					openId: openid
				}).then(res => {
					/* 人员列表 */
					if (res.rows.length > 0) {
						this.loadCardList({
							rows: JSON.parse(JSON.stringify(res.rows))
						})
					} else {
						this.visitList = []
						uni.removeStorageSync('currentVisitCard')
					}
				});
			},
			/* 加载就诊卡 */
			loadCardList(res) {
				this.visitList = res.rows
				let defaultCard = []
				/* 判断本地缓存 */
				if (uni.getStorageSync('currentVisitCard') != '') {
					defaultCard.push(JSON.parse(uni.getStorageSync('currentVisitCard')))
				} else {
					defaultCard = res.rows.filter(item => item.isDefault == '1')
				}
				if (defaultCard.length != 0) {
					uni.setStorageSync('currentVisitCard', JSON.stringify(defaultCard[0]))
					this.currentVisitInfo.name = defaultCard[0].name
					this.currentVisitInfo.cardNum = defaultCard[0].cardNum
					this.currentVisitInfo.qrCode = defaultCard[0].qrCode
					let a = defaultCard[0]
					if (a.relation == '1') { //本人
						if (a.headImg != null && a.headImg != '') {
							this.currentVisitInfo.headImg = a.headImg
						} else {
							this.currentVisitInfo.headImg = a.sex == '0' ? require(
								'@/static/images/homeIndex/patient-g.png') : a.sex == '1' ? require(
								'@/static/images/homeIndex/patient-m.png') : ''
						}
					} else {
						this.currentVisitInfo.headImg = a.sex == '0' ? require(
								'@/static/images/homeIndex/patient-g.png') : a.sex == '1' ? require(
								'@/static/images/homeIndex/patient-m.png') :
							''
					}
				} else {
					uni.setStorageSync('currentVisitCard', JSON.stringify(res.rows[0]))
					this.currentVisitInfo.name = res.rows[0].name
					this.currentVisitInfo.cardNum = res.rows[0].cardNum
					this.currentVisitInfo.qrCode = res.rows[0].qrCode
					let a = res.rows[0]
					if (a.relation == '1') { //本人
						if (a.headImg != null && a.headImg != '') {
							this.currentVisitInfo.headImg = a.headImg
						} else {
							this.currentVisitInfo.headImg = a.sex == '0' ? require(
								'@/static/images/homeIndex/patient-g.png') : a.sex == '1' ? require(
								'@/static/images/homeIndex/patient-m.png') : ''
						}
					} else {
						this.currentVisitInfo.headImg = a.sex == '0' ? require(
								'@/static/images/homeIndex/patient-g.png') : a.sex == '1' ? require(
								'@/static/images/homeIndex/patient-m.png') :
							''
					}
				}
			},
			/* 获取院内动态 */
			getTrends() {
				return new Promise((resolve, reject) => {
					getTrtendsList({
						hospitalCode: this.hospitalCode
					}).then(res => {
						resolve(res)
					});
				});
			},
			/* 获取底部医生列表 */
			getDoctor() {
				return new Promise((resolve, reject) => {
					getDoctorList({
						hospitalCode: this.hospitalCode,
						isShow: '1'
					}).then(res => {
						res.rows.forEach(item => {
							if (item.doctorImg) {
								// 替换域名
								let imgurl = item.doctorImg;
								let index = imgurl.indexOf('/profile');
								let urlParts = imgurl.slice(index);
								item.doctorImg = config.baseUrl + urlParts;
								console.log('urlParts==',urlParts)
								console.log('item.doctorImg==',item.doctorImg)
							}
						});
						resolve(res)
					});
				});
			},
			/* 获取底部科室列表 */
			getDept() {
				return new Promise((resolve, reject) => {
					getDeptList({
						hospitalCode: this.hospitalCode,
						isShow: '1'
					}).then(res => {
						resolve(res)
					});

				});
			},
			/* 字典 */
			getDict() {
				getDictType({
					dictType: 'sys_relation',
				}).then(res => {
					if (res.code == 200) {
						res.rows.forEach(item => {
							this.relationTrans[item.dictValue] = item.dictLabel
						})
					}
				});
				getDictType({
					dictType: 'user_sex',
				}).then(res => {
					if (res.code == 200) {
						res.rows.forEach(item => {
							this.sexTrans[item.dictValue] = item.dictLabel
						})
					}
				});
			},
			/* 轮播图点击跳转 */
			swiperClick(item) {
				if (this.bannersList[item].adType != undefined) {
					this.jumpType(this.bannersList[item])
				}
			},
			/* 轮播分类跳转 */
			jumpType(res) {
				/* adType:1路由详情，2路由列表，3第三方url，4小程序 */
				if (res.adType == '1') {
					uni.navigateTo({
						url: '/pages/home/trendsDetail?id=' + res.id + '&titleName=' + res.titleName
					})
				}
			},
			/* 查看医生详情 */
			toDoctorDetail(res) {
				uni.navigateTo({
					url: '/pages/home/doctorDetail?id=' + res.id
				})
			},
			/* 查看科室详情 */
			toDeptDetail(res) {
				uni.navigateTo({
					url: '/pages/home/deptDetail?id=' + res.id + '&deptName=' + res.deptName + '&deptCode=' + res.deptCode
				})
			},
			/* 功能编辑 */
			editFunction() {
				uni.navigateTo({
					url: '/pages/home/allFunction'
				})
			},
			/* 展示就诊二维码 */
			showErcode() {
				let a = JSON.parse(uni.getStorageSync('currentVisitCard'))
				this.showVisitErcode = true
			},
			/* 关闭就诊人二维码 */
			closeErcode() {
				this.showVisitErcode = false
				// console.log('close');
			},
			/* 打开就诊人列表 */
			open() {
				this.showVisitCard = true
			},
			/* 关闭就诊人列表 */
			close() {
				this.showVisitCard = false
				let a = JSON.parse(uni.getStorageSync('currentVisitCard'))
				if (a.relation == '1') { //本人
					if (a.headImg != null && a.headImg != '') {
						this.currentVisitInfo.headImg = a.headImg
					} else {
						this.currentVisitInfo.headImg = a.sex == '0' ? require('@/static/images/homeIndex/doct-g.png') : a
							.sex == '1' ? require('@/static/images/homeIndex/doct-m.png') : ''
					}
				} else {
					this.currentVisitInfo.headImg = a.sex == '0' ? require('@/static/images/homeIndex/doct-g.png') : a
						.sex == '1' ? require('@/static/images/homeIndex/doct-m.png') : ''
				}

				this.currentVisitInfo.name = a.name
				this.currentVisitInfo.cardNum = a.cardNum
				this.currentVisitInfo.qrCode = a.qrCode
			},
			/* tables切换 */
			clickTabs(res) {
				this.showDeapartDoctor = res.index == 0 ? true : false
			},
			/* 选择院区 */
			selectHospital() {
				uni.navigateTo({
					url: '/pages/home/courtyardArea'
				})
			},
			/* 查看更多医生 */
			moreDoctor() {
				uni.navigateTo({
					url: '/pages/home/doctorList'
				})
			},
			/* 查看更多科室 */
			moreDept() {
				uni.navigateTo({
					url: '/pages/home/deptList'
				})
			},
			/* 预约挂号 */
			toRegister() {
				if (uni.getStorageSync('currentVisitCard') == '') {
					this.$tab.navigateTo('/pages/addHealthCard/index')
				} else {
					this.jumpTypeCode = '1'
					this.registerKnowe = true
				}
			},
			/* toMessage(){
				uni.navigateTo({
					url: '/pages/message/index'
				})
			}, */
			readDone() {
				this.registerKnowe = false
				if (this.jumpTypeCode == '1') {
					uni.navigateTo({
						url: '/pages/mine/selectDepartment/index?registerType=1'
					})
				}
				if (this.jumpTypeCode == '2') {
					uni.navigateTo({
						url: '/pages/mine/selectDepartment/index?registerType=2'
					})
				}
			},
			/* 就医缴费 */
			toRecharge() {
				if (uni.getStorageSync('currentVisitCard') == '') {
					this.$tab.navigateTo('/pages/addHealthCard/index')
				} else {
					uni.navigateTo({
						url: '/pages/pay/index'
					})
				}
			},
			/* 检查报告 */
			checkReport() {
				if (uni.getStorageSync('currentVisitCard') == '') {
					this.$tab.navigateTo('/pages/addHealthCard/index')
				} else {
					uni.navigateTo({
						url: '/pages/mine/report/index'
					})
				}

			},
			scroll(e) {

			}
		}
	}
</script>

<style scoped lang="scss">
	page {
		height: 100%;

		img {
			display: block;
		}

		.swiper {
			height: 200rpx;
		}

		.swiper-item {
			display: block;
			height: 200rpx;
			text-align: center;
		}

		.swiper-list {
			margin-top: 40rpx;
			margin-bottom: 0;
		}



		.content {
			width: 100%;
			height: 100%;



			.ercode-pop {
				width: 90%;
				margin-left: 5%;

				.avatar {
					width: 160rpx;
				}

				.ercode {
					width: 100%;
				}
			}


			.scroll-view_visit {
				width: 100%;
				height: 100%;

				.card-item {
					width: 94%;
					margin-left: 3%;
					margin-bottom: 20rpx;
					border-radius: 12rpx;
					background-color: #F8F8F8;

					.select-visit {
						padding: 8rpx 30rpx;
						background-color: #4D8EFF;
						color: #fff;
						border-radius: 12rpx;
					}
				}
			}




			.scroll-view_H {
				width: 100%;
				height: 100%;
				background-color: #F6F7F9;

				.swiper-module {
					width: 100%;
					background-color: #fff;

					.content {
						width: 94%;
						margin-left: 3%;

						.swiper-item {
							img {
								width: 100%;
							}
						}
					}
				}

				.department-doctor {
					width: 100%;
					// background-color: rgba(245, 245, 245, .9);
					background: linear-gradient(180deg, rgba(255, 255, 255, 0.5) 0%, rgba(245, 245, 245, 1) 100%);

					.content {
						width: 94%;
						margin-left: 3%;
						background-color: #fff;
						border-radius: 12rpx;

						.item {
							border-bottom: 1px solid #EEEEEE;
							padding-bottom: 20rpx;

							.avatar {
								width: 120rpx;
								height: 120rpx;
							}

							.overEllips {
								overflow: hidden;
								text-overflow: ellipsis;
								display: -webkit-box;
								-webkit-box-orient: vertical;
								-webkit-line-clamp: 2;
							}

						}

						.more {
							border-radius: 10rpx;
							background: rgba(22, 119, 255, .1);
						}

					}
				}


				.function-module {
					width: 100%;
					background-color: #fff;

					.ico-shadow {
						padding: 20rpx;
						border-radius: 35rpx;
						background: rgba(77, 142, 255, 0.1);

						img {
							display: block;
						}
					}

					.content {
						width: 94%;
						margin-left: 3%;

						.item {
							width: 25%;

							text {
								color: #323232;
							}
						}
					}
				}


				.visit-function {
					width: 100%;
					background-color: #fff;
					border-radius: 0 0 20rpx 20rpx;

					.content {
						width: 94%;
						margin-left: 3%;

						.register {
							flex: 1;
							border-radius: 12rpx;
							background: linear-gradient(134.51deg, #50DA86 0%, #2FCE95 100%);
							height: 190rpx;
							position: relative;

							.bottom-icon {
								position: absolute;
								bottom: -16rpx;
								right: -10rpx;
							}
						}

						.pay {
							flex: 1;
							border-radius: 12rpx;
							background: linear-gradient(134.51deg, #5E96F7 0%, #4D8EFF 100%);
							margin: 0 16rpx;
							height: 190rpx;
							position: relative;

							.bottom-icon {
								position: absolute;
								bottom: -12rpx;
								right: -10rpx;
							}
						}

						.report {
							flex: 1;
							border-radius: 12rpx;
							background: linear-gradient(134.51deg, #FFA58F 0%, #FF907B 100%);
							height: 190rpx;
							position: relative;

							.bottom-icon {
								position: absolute;
								bottom: -16rpx;
								right: -16rpx;
							}
						}
					}
				}


				.current-visit-card {
					width: 100%;
					height: 160rpx;
					background-color: #fff;
					position: relative;

					.content {
						position: absolute;
						top: -70rpx;
						width: 94%;
						height: 220rpx;
						margin-left: 3%;
						padding: 30rpx 40rpx;
						background-color: #DDEBFE;
						border-radius: 18rpx;
						box-shadow: 0px 1px 2px #3C537D;

						.ercode {
							width: 160rpx;

						}

						.switch-but {
							background: linear-gradient(90deg, #4D8EFF 0%, #5E96F7 100%);
							border-radius: 10rpx;
						}
					}
				}

				.courtyard-area {
					position: relative;

					.hosp-name {
						position: absolute;
						left: 3%;
						top: 28%;

						text {
							font-size: 36rpx;
							color: #fff;
						}

						img {
							width: 24rpx;
						}
					}
				}
			}

		}
	}
</style>